package com.khyr.controller;

import com.khyr.entity.SysRegisteredItem;
import com.khyr.feign.UserFeign;
import com.khyr.service.RegisteredService;
import com.khyr.vo.*;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：Zhang
 * @date ：Created in 2025/3/13 17:04
 * @description：门诊挂号
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/seeADoctor/Registered")
public class RegisteredController {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private UserFeign userFeign;
    @Autowired
    private RegisteredService registeredService;
    /**
     * @create by: Zr
     * @description: 挂号项目信息
     * @create time: 2025/3/13 19:00
     * @param
     * @return com.khyr.vo.R<java.util.List<com.khyr.entity.SysRegisteredItem>>
     */
    @GetMapping("/getAllRegisteredItem")
    public R<List<SysRegisteredItem>> getAllRegisteredItem(){
        return registeredService.getAllRegisteredItem();
    }
    /**
     * @create by: Zr
     * @description: 根据科室，时间，类型查询可挂号的信息
     * @create time: 2025/3/13 20:30
     * @param data
     * @return com.khyr.vo.R<java.util.List<com.khyr.vo.FindSchedulingListDto>>
     */
    @PostMapping("/findSchedulingList")
    public R<List<FindSchedulingListDto>> findSchedulingList(@RequestBody FindSchedulingListVo data){
        return registeredService.findSchedulingList(data);
    }
    /**
     * @create by: Zr
     * @description: 添加挂号信息
     * @create time: 2025/3/14 11:35
     * @param data
     * @return com.khyr.vo.R<java.lang.String>
     */
    @PostMapping("/addRegistration")
    public R<String> addRegistration(@RequestBody FindSchedulingListAndPatientVo data){
        String token = request.getHeader("token");
        String name=userFeign.getUserInfo(token).getData().getUserName();
        return registeredService.addRegistration(data,name);
    }
    /**
     * @create by: Zr
     * @description: 用于添加手机端的挂号信息
     * @create time: 2025/3/18 16:45
     * @param data
     * @return com.khyr.vo.R<java.lang.String>
     */
    @PostMapping("/addAppRegistration")
    public R<String> addAppRegistration(@RequestBody addAppRegistrationVo data){
        String token = request.getHeader("token");
        if(userFeign.getPatientInfo(token).getData()!=null){
            String patientId=userFeign.getPatientInfo(token).getData().getPatientId();
            String name = userFeign.getPatientInfo(token).getData().getName();
            return registeredService.addAppRegistration(data,patientId,name);
        }
        return new R<>(500,"请先完善个人信息",null);

    }
    /**
     * @create by: Zr
     * @description: 根据挂号流水号GH_ID收费
     * @create time: 2025/3/14 11:35
     * @param registrationId
     * @return com.khyr.vo.R<java.lang.String>
     */
    @GetMapping("/collectFee/{registrationId}")
    public R<String> collectFee(@PathVariable String registrationId){
        return registeredService.collectFee(registrationId);
    }

}
